home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / ML_BME1.ZIP / PLASMA / GENP4.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-12-21  |  1.7 KB  |  73 lines

  1. // *************************************************************************
  2. //  Plasma cloud generator
  3. //  by Maple Leaf, Dec 1996
  4. //  -----------------------------------------------------------------------
  5. //  No rights reserved
  6. // *************************************************************************
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <math.h>
  11.  
  12. void    main()
  13. {
  14.     float    x,y,count,i;
  15.     int    lead,offset;
  16.     FILE    *fp;
  17.     unsigned char value;
  18.  
  19.     printf("\nPlasma generator, by Maple Leaf, 1996\n\nProcessing ...!\n");
  20.  
  21.     if (!(fp=fopen("PLASMA.DAT","wb")))
  22.     {
  23.         printf("\7Cant open output file PLASMA.DAT\n");
  24.         exit(255);
  25.     }
  26.  
  27.     /* First generate the plasma map.  This is effectively just an
  28.        arbitrary function of x and y which gives a smooth but
  29.        non-uniform surface */
  30.  
  31.  
  32.     for (y=0;y<300;y++)
  33.     for (x=0;x<512;x++)
  34.     {
  35.         value=64+10*( sin(x/20) + cos(y/180) +
  36.                   cos(x/40) + sin(y/70) +
  37.                   sin((x+2*y)/70) +
  38.                   cos(hypot(256-x,150-y)/10)
  39.                   );
  40.         fputc(value,fp);
  41.     }
  42.  
  43.     /* Then arbitrary movement for two pointers */
  44.  
  45.     for (count=0;count<10000;count++)
  46.     {
  47.         lead=           96+92*cos(count/32)
  48.              +512*(int)(48+47*sin(count/16));
  49.         offset=         96+92*sin(count/21)
  50.              +512*(int)(48+47*cos(count/24))
  51.              -lead;
  52.         fwrite(&lead,2,1,fp);
  53.         fwrite(&offset,2,1,fp);
  54.     }
  55.  
  56.     /* And a smooth transition colour lookup table */
  57.  
  58.     for (i=-256; i<256*39; i++)
  59.         if (i<0)
  60.         {
  61.             fputc(0,fp);
  62.             fputc(0,fp);
  63.             fputc(0,fp);
  64.         }
  65.         else
  66.         {
  67.             fputc((sin(i/200)*cos(i/300)*31+31),fp);
  68.             fputc((cos(i/400)*cos(i/300)*31+31),fp);
  69.             fputc((sin(i/100)*cos(i/10)*31+31),fp);
  70.         }
  71.     fclose(fp);
  72. }
  73.